var __extends =
    (this && this.__extends) ||
    (function () {
      var e = function (t, r) {
        return (e =
          Object.setPrototypeOf ||
          ({ __proto__: [] } instanceof Array &&
            function (e, t) {
              e.__proto__ = t;
            }) ||
          function (e, t) {
            for (var r in t)
              Object.prototype.hasOwnProperty.call(t, r) && (e[r] = t[r]);
          })(t, r);
      };
      return function (t, r) {
        function a() {
          this.constructor = t;
        }
        if ("function" != typeof r && null !== r)
          throw new TypeError(
            "Class extends value " + String(r) + " is not a constructor or null"
          );
        e(t, r),
          (t.prototype =
            null === r
              ? Object.create(r)
              : ((a.prototype = r.prototype), new a()));
      };
    })(),
  TradeView = (function (e) {
    function t() {
      var t = e.call(this) || this;
      return (
        (t.price_num = 0),
        (t.sales_num = 0),
        (t.trade_type = 0),
        (t.spaceTime = 0),
        (t.onLoadOrderRecordDataListFn = {
          caller: t,
          code: 1456,
          method: function (e) {
            var r = e.list;
            t.orderArr = [];
            for (var a, n = 0; n < r.length; n++)
              (a = {
                order_Index: { text: n + 1 },
                lbl_charge_time: t.dateStringFormate(r[n].creation_date),
                lbl_descr_msg:
                  r[n].price +
                  " 银 " +
                  t.dealSaleStateFn(r[n].shop_type) +
                  r[n].count +
                  "个 ( " +
                  t.dealChargeStateFn(r[n].state) +
                  " )",
                order_id: r[n].id,
                order_type: r[n].shop_type,
                state: r[n].state,
              }),
                t.orderArr.push(a);
            t.list_order_charge.array = t.orderArr;
          },
        }),
        (t.onLoadCancleOrderDataFn = {
          caller: t,
          code: 1467,
          method: function (e) {
            0 == e.code
              ? (ToastView.toastView("撤销成功"),
                WebSocketService.send({ c: 1456, d: { pageNum: 0 } }))
              : ToastView.toastView(e.msg);
          },
        }),
        (t.onLookingBricsDataFn = {
          caller: t,
          code: 1463,
          method: function (e) {
            0 == e.code
              ? (ToastView.toastView("交易成功"),
                (t.text_saleNumber.text = ""),
                (t.text_salesprice.text = ""),
                WebSocketService.send({ c: 210, d: { no: 3 } }),
                0 == t.tab_trade.selectedIndex &&
                  WebSocketService.send({ c: 1455, d: { type: 1 } }),
                1 == t.trade_type ||
                  WebSocketService.send({ c: 1456, d: { pageNum: 0 } }))
              : ToastView.toastView(e.msg);
          },
        }),
        (t.onSupplyInformationFn = {
          caller: t,
          code: 1455,
          method: function (e) {
            if (0 == e.code) {
              if (((t.objDict = e), t.currentPage >= 1)) {
                if (0 == e.list.length) return void t.currentPage--;
                for (s = 0; s < e.list.length; s++) {
                  var r = e.list[s];
                  t.listArr.push(r), (t.dataSource = []);
                }
              } else (t.listArr = e.list), (t.dataSource = []);
              t.listArr.length > 0 && (t.list_trade_supply.visible = !0),
                (t.isloading = !1);
              var a = t.listArr;
              (t.supplyArr = []), (t.giverArr = []);
              for (var n, i, o = [], s = 0; s < a.length; s++)
                1 == a[s].type
                  ? ((n = {
                      lbl_flyIndex: { text: s + 1 },
                      lbl_supply_message:
                        a[s].price + "银  ( 求 " + a[s].count + " 个）",
                    }),
                    t.supplyArr.push(n))
                  : 2 == a[s].type &&
                    (o.push(a[s]),
                    (i = {
                      lbl_flyIndex: { text: s + 1 },
                      lbl_supply_message:
                        a[s].price + "银  ( 供 " + a[s].count + " 个）",
                    }),
                    t.giverArr.push(i));
              0 == t.tab_charge_gold.selectedIndex
                ? t.dealMathMaxValue(o)
                : t.dealExitMsg(t.trade_type),
                (t.list_trade_supply.array = t.supplyArr),
                (t.list_trade_giver.array = t.giverArr);
            }
          },
        }),
        (t.tradeMoneyFn = {
          caller: t,
          code: 1450,
          method: function (e) {
            (t.lbl_carryGold.text = e.data.gold),
              (t.lbl_carrySliver.text = e.data.money),
              Laya.stage.event("HomePageView", { code: "moeny", data: e.data });
          },
        }),
        t.tab_charge_gold.on(Laya.Event.CLICK, t, t.onChargeGoldMoneyFuntion),
        t.tab_trade.on(Laya.Event.CLICK, t, t.onTardeSelectFn),
        t.btn_tradePreBack.on(Laya.Event.CLICK, t, t.onTradePreBackFn),
        t.btn_confirmbuy.on(Laya.Event.CLICK, t, t.onConfirmBuyFn),
        t.btn_price_cut.on(Laya.Event.CLICK, t, t.onSaleMessageInputFn),
        t.btn_price_plus.on(Laya.Event.CLICK, t, t.onSaleMessageInputFn),
        t.btn_number_cut.on(Laya.Event.CLICK, t, t.onSaleMessageInputFn),
        t.btn_number_plus.on(Laya.Event.CLICK, t, t.onSaleMessageInputFn),
        WebSocketService.addListener(t.tradeMoneyFn),
        WebSocketService.addListener(t.onSupplyInformationFn),
        WebSocketService.addListener(t.onLoadOrderRecordDataListFn),
        WebSocketService.addListener(t.onLookingBricsDataFn),
        WebSocketService.addListener(t.onLoadCancleOrderDataFn),
        (t.list_order_charge.vScrollBarSkin = ""),
        (t.list_order_charge.selectEnable = !0),
        t.list_order_charge.on(Laya.Event.CLICK, t, t.onOrderChargeClickFn),
        (t.list_order_charge.renderHandler = new Handler(
          t,
          t.onUpdateTradeItem
        )),
        (t.list_order_charge.scrollBar.changeHandler = new Handler(
          t,
          t.onLoadMoreEquimentData
        )),
        t
      );
    }
    return (
      __extends(t, e),
      (t.openView = function () {
        return (
          null == this.tradeVC && (this.tradeVC = new t()),
          (this.tradeVC.trade_type = 1),
          (this.tradeVC.image_supply.visible = !0),
          (this.tradeVC.image_order.visible = !1),
          (this.tradeVC.listArr = []),
          (this.tradeVC.objDict = {}),
          (this.tradeVC.tab_charge_gold.selectedIndex = 0),
          (this.tradeVC.tab_trade.selectedIndex = 0),
          (this.tradeVC.currentPage = 0),
          WebSocketService.send({ c: 210, d: { no: 3 } }),
          WebSocketService.send({ c: 1455, d: { type: 1 } }),
          this.tradeVC
        );
      }),
      (t.prototype.onLoadMoreEquimentData = function (e) {
        var t = e / this.list_order_charge.scrollBar.max,
          r = new Date(),
          a = !1;
        if (
          (r.getTime() - this.spaceTime >= 3e3 && (a = !0),
          1 == t && 0 == this.isloading && a)
        )
          return (
            (this.isloading = !0),
            this.currentPage++,
            1 == this.tab_trade.selectedIndex &&
              WebSocketService.send({
                c: 1456,
                d: { pageNum: this.currentPage },
              }),
            void (this.spaceTime = r.getTime())
          );
      }),
      (t.prototype.onUpdateTradeItem = function (e, t) {
        if (!(t > this.orderArr.length)) {
          var r = e.getChildByName("btn_chexiao_charge"),
            a = this.orderArr[t].state;
          r.visible = 2 != a;
        }
      }),
      (t.prototype.onOrderChargeClickFn = function (e) {
        if ("btn_chexiao_charge" == e.target.name) {
          var t = this.orderArr[this.list_order_charge.selectedIndex].order_id,
            r = this.orderArr[this.list_order_charge.selectedIndex].order_type;
          WebSocketService.send({ c: 1467, d: { type: r, orderId: t } });
        }
      }),
      (t.prototype.dealSaleStateFn = function (e) {
        return 1 == e ? "求购" : 2 == e ? "出售" : "";
      }),
      (t.prototype.dealChargeStateFn = function (e) {
        return 0 == e
          ? "未成交"
          : 1 == e
          ? "部分成交"
          : 2 == e
          ? "已经成交"
          : 3 == e
          ? "撤单"
          : "";
      }),
      (t.prototype.onChargeGoldMoneyFuntion = function (e) {
        "item0" == e.target.name
          ? ((this.lbl_price_title.text = "求购单价："),
            (this.lbl_number_title.text = "求购数量："),
            (this.btn_confirmbuy.label = "确定求购"),
            (this.trade_type = 1))
          : "item1" == e.target.name &&
            ((this.lbl_price_title.text = "供货单价："),
            (this.lbl_number_title.text = "供货数量："),
            (this.btn_confirmbuy.label = "确定供货"),
            (this.trade_type = 2)),
          this.dealExitMsg(this.trade_type);
      }),
      (t.prototype.dealExitMsg = function (e) {
        var t = this.objDict.list;
        if (void 0 != t) {
          for (var r = [], a = [], n = 0; n < t.length; n++) {
            var i = t[n];
            1 == i.type ? r.push(i) : a.push(i);
          }
          if (1 == e) this.text_salesprice.text = a[0].price;
          else {
            var o = r.length;
            this.text_salesprice.text = r[o - 1].price;
          }
        }
      }),
      (t.prototype.dealMathMaxValue = function (e) {
        for (var t = 0, r = 0; r < e.length; r++) {
          0 == r && (t = e[r].price);
          var a = e[r].price;
          t > a && (t = a);
        }
        t > 0 && (this.text_salesprice.text = t + "");
      }),
      (t.prototype.onTardeSelectFn = function (e) {
        "" != e.target.name &&
          ("item0" == e.target.name
            ? ((this.image_supply.visible = !0),
              (this.image_order.visible = !1),
              WebSocketService.send({ c: 1455, d: { type: 1 } }))
            : "item1" == e.target.name &&
              ((this.image_supply.visible = !1),
              (this.image_order.visible = !0),
              WebSocketService.send({ c: 1456, d: { pageNum: 0 } })));
      }),
      (t.prototype.onConfirmBuyFn = function () {
        var e = parseInt(this.text_salesprice.text),
          t = parseInt(this.text_saleNumber.text);
        e <= 0
          ? ToastView.toastView("请输入单价")
          : t <= 0
          ? ToastView.toastView("请输入数量")
          : WebSocketService.send({
              c: 1463,
              d: { type: this.trade_type, count: t, price: e },
            });
      }),
      (t.prototype.onSaleMessageInputFn = function (e) {
        var t = parseInt(this.text_salesprice.text),
          r = parseInt(this.text_saleNumber.text);
        isNaN(t) && (t = 0),
          isNaN(r) && (r = 0),
          "item_cut1" == e.target.name
            ? (t += -1) >= 0
              ? (this.text_salesprice.text = t + "")
              : (t = 0)
            : "item_plus1" == e.target.name
            ? (t += 1) >= 0
              ? (this.text_salesprice.text = t + "")
              : (t = 0)
            : "item_cut2" == e.target.name
            ? (r += -1) >= 0
              ? (this.text_saleNumber.text = r + "")
              : (t = 0)
            : "item_plus2" == e.target.name &&
              ((r += 1) >= 0 ? (this.text_saleNumber.text = r + "") : (t = 0));
      }),
      (t.prototype.dateStringFormate = function (e) {
        return (
          e.substring(5, 7) +
          "月" +
          e.substring(8, 10) +
          "日 " +
          e.substring(11, 13) +
          ":" +
          e.substring(14, 16)
        );
      }),
      (t.prototype.onTradePreBackFn = function () {
        this.removeSelf();
      }),
      t
    );
  })(ui.MoneyBankController.TradeViewUI);
